package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lixu
 */
@RestController
@RequestMapping("/admin/user")
@CrossOrigin
public class UserController {

    @Autowired
    private DtsUserService dtsUserService;

    /**
     * http://localhost:8083/admin/user/list?page=1&limit=20&sort=add_time&order=desc
     * 请求方法: GET
     */
    @RequiresPermissions(value = "admin:user:list")
    @RequiresPermissionsDesc(menu = {"用户管理","会员管理"},button = "查询")
    @GetMapping("/list")
    public Object list(String nickname,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "20") Integer limit,
                       String sort,
                       String order,
                       String mobile){
        //分页
        IPage<DtsUser> iPage = dtsUserService.findListByQuery(nickname,page,limit,sort,order,mobile);
        Map data = new HashMap<>();
        data.put("total", iPage.getTotal());
        data.put("items", iPage.getRecords());
        return ResponseUtil.ok(data);
    }
    /**
     * - 接口地址 : http://localhost:8083/admin/user/approveAgency
     * - 下行数据 :
     */
    @RequiresPermissionsDesc(menu = {"用户管理","会员管理"},button = "会员审批")
    @RequiresPermissions(value = "admin:user:approveAgency")
    @GetMapping("/approveAgency")
    public Object approveAgency(){
        return ResponseUtil.ok();
    }
    /**
     * 会员推广代理
     * - 接口地址 : http://localhost:8083/admin/user/detailApprove?id=71
     *
     * - 下行数据 :
     */
    @RequiresPermissionsDesc(menu = {"用户管理","会员管理"},button = "会员推广代理")
    @RequiresPermissions(value = "admin:user:detailApprove")
    @GetMapping("/detailApprove")
    public Object detailApprove(Integer id){
        return ResponseUtil.ok();
    }
}
